<template>

<el-container class="home-container">
  <!-- 头部 -->
  <el-header>
      <div>
          <span>题库后台管理系统</span>
      </div>
<el-dropdown @command="handleCommand">
  <span class="el-dropdown-link">
   {{username}}<i class="el-icon-arrow-down el-icon--right"></i>
  </span>
  <el-dropdown-menu slot="dropdown">
    <el-dropdown-item command="logout">退出</el-dropdown-item>
  </el-dropdown-menu>
</el-dropdown>
  </el-header>
  <!-- 页面主题 -->
  <el-container>
      <!-- 侧边栏 -->
    <el-aside :width="isCollage?'64px':'200px'">
        <div class="toggle-button" @click="toggleCollage">|||</div>
        
        
        <el-menu
     
      background-color="#72c3f1"
      text-color="#fff"
      active-text-color="#fff"
      unique-opened
      :collapse='isCollage'
      :collapse-transition='false'
      :router="true"
      :default-active="activePath">
      <!-- 一级菜单 -->
      <el-submenu :index="item.id+''" v-for="item in menuList" :key="item.id" >
          <!-- 一级菜单模板 -->
        <template slot="title">
          
          <span>{{item.authName}}</span>
        </template>
       
      
        <!-- 二级菜单 -->
          <el-menu-item :index="'/'+subItem.path" v-for="subItem in item.children" :key="subItem.id"
          @click="saveNavState('/'+subItem.path)">
              <template slot="title">
         
          <span>{{subItem.authName}}</span>
        </template>
        </el-menu-item>
        
      </el-submenu>
 
    </el-menu>
    </el-aside>
    <!-- 右边主体内容 -->
    <el-main><router-view></router-view></el-main>
  </el-container>
</el-container>
</template>
<script>
export default {
    data(){
        return{
            menuList:[{id:1,authName: "题目管理",children:[{id:11,authName: "题目列表",path:'exercises'}]},
            {id:2,authName: "投诉管理",children:[ {id:21,authName: "投诉内容",path:'complaint'}]},
        
           ],
         username:'',
            isCollage:false,
            activePath:''
        }
    },
    created(){
     this.username=window.sessionStorage.getItem('userinfo')
        this.activePath=window.sessionStorage.getItem('activePath')
    
    },
    methods:{
  
        toggleCollage(){
            this.isCollage=!this.isCollage
        },
        logout(){
            console.log(1);
            window.sessionStorage.clear()
            this.$router.push('/login')
        },
        //下拉菜单的事件
          handleCommand(command) {
       if(command==='logout'){
           this. logout()
       }
      },

        //保持链接激活状态
        saveNavState(activePath){
window.sessionStorage.setItem('activePath',activePath)
this.activePath=activePath
        }
    }
}
</script>
<style lang="less" scoped>
.home-container{
    height: 100vh;
}

.el-header{
    display: flex;
    justify-content: space-between;
    background-color: skyblue;
    padding-left: 0;
    align-items: center;
    font-size: 20px;
    color: #fff;
    >div{
        display: flex;
        align-items: center;
    }
    span{
        margin: 15px;}
}
.el-aside{
    background-color: skyblue;
    .el-menu{
        border-right: 0;
    }
}
.el-main{
    background-color:whitesmoke;
}
.iconfont{
    margin-right: 10px;
}
.toggle-button{
    background-color: #72c3f1;
    color: white;
    font-size: 10px;
    line-height: 24px;
    text-align: center;
    cursor: pointer;
}
 .el-dropdown-link {
    cursor: pointer;
    color: #fff;
  }
</style>
